Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

189
Vistas
Getting Error: "TypeError: Cannot read property 'channels' of undefined"

Here's my code:

module.exports = {
    name: 'suggestions',
    aliases: ['suggest'],
    execute(message, args, cmd, client, discord) {
        let channel = message.guild.channel.cache.find(ch=>ch.id==='890313569260937247')
        if(!channel) return message.channel.send({ content: 'There is no suggestion channel on this Server!' });

        let messageArgs = args.join(' ')
        const embed = new Discord.MessageEmbed()
        .setColor('#008000')
        .setAuthor(message.author.tag)
        .setDescription(messageArgs)
        .setTitle(`${message.author.tag} has a suggestion!!`)

        message.channel.send({ embeds: [embed] })
    }
}

I'm basically creating a command with my command Handler, doing a suggestion command, where the arguments of an user are going to be sent in a MessageEmbed.

If I run the actual command, this error shows up:

TypeError: Cannot read property 'channel' of undefined
    at Object.execute (D:\Programming\Workspaces\Discord Bots\Mita Bot v1\commands\suggestions.js:5:37)
    at module.exports (D:\Programming\Workspaces\Discord Bots\Mita Bot v1\events\guild\message.js:11:25)
    at Client.emit (node:events:394:28)
    at MessageCreateAction.handle (D:\Programming\Workspaces\Discord Bots\Mita Bot v1\node_modules\discord.js\src\client\actions\MessageCreate.js:31:18)
    at Object.module.exports [as MESSAGE_CREATE] (D:\Programming\Workspaces\Discord Bots\Mita Bot v1\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (D:\Programming\Workspaces\Discord Bots\Mita Bot v1\node_modules\discord.js\src\client\websocket\WebSocketManager.js:345:31)
    at WebSocketShard.onPacket (D:\Programming\Workspaces\Discord Bots\Mita Bot v1\node_modules\discord.js\src\client\websocket\WebSocketShard.js:443:22)
    at WebSocketShard.onMessage (D:\Programming\Workspaces\Discord Bots\Mita Bot v1\node_modules\discord.js\src\client\websocket\WebSocketShard.js:300:10)
    at WebSocket.onMessage (D:\Programming\Workspaces\Discord Bots\Mita Bot v1\node_modules\discord.js\node_modules\ws\lib\event-target.js:132:16)
    at WebSocket.emit (node:events:394:28)
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

As t.niese said in their comment, Message#guild can be null. If message.guild === null, this means the message was sent in a DM.

Check if the message was sent in a guild first:

if (!message.guild)
  return message.channel.send('This command can only be used in a server!')

const channel = message.guild.channels.get('890313569260937247')
if (!channel)
  return message.channel.send('There is no suggestion channel on this Server!')

Some other points:

  • There is no channel property on Guild; use channels instead.
  • You can use Collection#get to get a channel by its id (no need to use .find(c => c.id === someId).
  • You can use a string directly in send: channel.send('the message') instead of channel.send({ content: 'the message' }).
about 4 years ago · Juan Pablo Isaza Denunciar

0

'channel' is not a property of the Guild class, you probably meant Guild#channels which returns the necessary type of GuildChannelManager.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda